﻿//namespace Common.Extensions
//{

using System;
using System.Globalization;
using System.Linq;
using System.Text;

public static class StringExtensions
    {
        private const string EMPTY = "";
        private const string WHITESPACE = " ";

        public static string RemoveWhitespaces(this string text, string replacement = EMPTY)
        {
            return text.Replace(WHITESPACE, replacement).Trim();
        }

        public static bool IsEqualTo(this string str1, string str2)
        {
            return String.Equals(str1.Trim(), str2.Trim(), StringComparison.CurrentCultureIgnoreCase);
        }

        // Reference: http://www.levibotelho.com/development/c-remove-diacritics-accents-from-a-string/
        public static string RemoveDiacritics(this string text)
        {
            if (string.IsNullOrWhiteSpace(text))
                return text;
            text = text.Normalize(NormalizationForm.FormD);
            var chars = text.Where(c => CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark).ToArray();
            return new string(chars).Normalize(NormalizationForm.FormC);
        }
    }
//}
